package com.keepmoving.service.impl;

import com.keepmoving.dao.LoginDao;
import com.keepmoving.po.Login;
import com.keepmoving.service.LoginService;
import com.keepmoving.util.MD5Util;
import org.junit.Test;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author gyy
 * 登录的业务逻辑实现类
 */
@Service
public class LoginServiceImpl implements LoginService {
    @Resource
    LoginDao loginDao;

    @Test
    public void test(){
        Login login = new Login(100001,"gyy","123456",3);
        int i = addLogin(login);
        System.out.println(i);
    }
    @Override
    public Login loginByLId(Login login) {
        String pass1=login.getlPass();
        String pass2=MD5Util.md5(pass1);
        login.setlPass(pass2);
        return loginDao.loginByLId(login);
    }

    @Override
    public Login login(Login login) {
        String lPass=login.getlPass();
        String s= MD5Util.md5(lPass);
        return loginDao.login(login);
    }

    @Override
    public int addLogin(Login login) {
        String lpass=MD5Util.md5(login.getlPass());
        login.setlPass(lpass);
        loginDao.addLogin(login);
        return login.getlId();
    }

    @Override
    public boolean updatePass(Login login) {
        String lpass1=MD5Util.md5(login.getlPass());
        login.setlPass(lpass1);
        return loginDao.updatePass(login)>0? true:false;
    }
}
